    package com.idc.test;
    
    import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;

import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
    
    public class ExcelExportDemo {
        public static void main(String[] args) {
            List<User> users = new ArrayList<>();
			users.add(new User("张三", 10000.0, 0.1, null));
			users.add(new User("李四", 15000.0, 0.15, null));
            String fileName = "user_bonus.xlsx";
            // 写入数据并注册公式处理器
            ExcelWriter excelWriter = EasyExcel.write(fileName, User.class)
                    .registerWriteHandler(new BonusFormulaHandler())
                    .build();
            
            WriteSheet writeSheet = EasyExcel.writerSheet("奖金计算").build();
            excelWriter.write(users, writeSheet);
            excelWriter.finish();
    
            // 强制计算公式结果
            try (FileInputStream fis = new FileInputStream(fileName);
                 Workbook workbook = WorkbookFactory.create(fis)) {
                FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
				evaluator.evaluateAll();
                try (FileOutputStream fos = new FileOutputStream(fileName)) {
                    workbook.write(fos);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
